package com.auto.code.core.enums;

/**
 * 
 * @desc 数据类型转换
 * @author meikb
 * @date 2019年9月29日	
 *
 */
public enum TypeConvertEnum {
    //------------------------------------------------------------
    MYSQL_BIGINT("bigint", GenFieldType.LONG),
    MYSQL_BIT("bit", GenFieldType.INTEGER),
    MYSQL_ENUM("enum", GenFieldType.STRING),
    MYSQL_CHAR("char", GenFieldType.STRING),
    MYSQL_DATE("date", GenFieldType.DATE),
    MYSQL_DATE2("datetime", GenFieldType.DATE),
    MYSQL_DECIMAL("decimal", GenFieldType.BIG_DECIMAL),
    MYSQL_NUMERIC("numeric", GenFieldType.BIG_DECIMAL),
    MYSQL_DOUBLE("double", GenFieldType.DOUBLE),
    MYSQL_BLOB("blob", GenFieldType.BYTE_ARR),
    MYSQL_MEDIUMBLOB("mediumblob", GenFieldType.BYTE_ARR),
    MYSQL_LONGBLOB("longblob", GenFieldType.BYTE_ARR),
    MYSQL_FLOAT("float", GenFieldType.FLOAT),
    MYSQL_INT("int", GenFieldType.INTEGER),
    MYSQL_SMALLINT("smallint", GenFieldType.INTEGER),
    MYSQL_TINYINT("tinyint", GenFieldType.INTEGER),
    SMALLINT_TINYINT("smallint", GenFieldType.INTEGER),
    MYSQL_BINARY("binary", GenFieldType.BYTE_ARR),
    MYSQL_VARCHAR("varchar", GenFieldType.STRING),
    MYSQL_TINYTEXT("tinytext", GenFieldType.STRING),
    MYSQL_TEXT("text", GenFieldType.STRING),
	MYSQL_LONG_TEXT("longtext", GenFieldType.STRING)
	
	;
	
    private String dbType;
    private GenFieldType type;

    TypeConvertEnum(String dbType, GenFieldType type) {
        this.dbType = dbType;
        this.type = type;
    }

    public static String getTypeByDb( String dbType) {
        TypeConvertEnum[] types = TypeConvertEnum.values();
        for (int i = 0; i < types.length; i++) {
            if (types[i].dbType.equalsIgnoreCase(dbType)) {
                return types[i].type.getType();
            }
        }
        return null;
    }

    public String getDbType() {
        return dbType;
    }

    public GenFieldType getType() {
        return type;
    }
}
